package com.trazy.persistence.configuration;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public abstract class ServicePackageConfiguration extends AbstractConfiguration {

	private Set<ServicePackageConfiguration> dependancies = new HashSet<ServicePackageConfiguration>();

	protected abstract List<String> getLocalClientConfigurationLocations();

	protected abstract List<String> getLocalServerConfigurationLocations();

	protected Set<ServicePackageConfiguration> getLocalDependencies() { return Collections.emptySet(); };

	public Set<String> getClientConfigurationLocations() {
		Set<String> configs = new HashSet<String>(getLocalClientConfigurationLocations());
		for (ServicePackageConfiguration dependancy : dependancies) {
			Set<String> dependancyConfigs = dependancy.getClientConfigurationLocations();
			configs.addAll(dependancyConfigs);
		}
		return configs;
	}

	public Set<String> getServerConfigurationLocations() {
		Set<String> configs = new HashSet<String>(getLocalServerConfigurationLocations());
		for (ServicePackageConfiguration dependancy : dependancies) {
			Set<String> dependancyConfigs = dependancy.getServerConfigurationLocations();
			configs.addAll(dependancyConfigs);
		}
		return configs;
	}

	public Set<String> getConfigurationLocations() {
		Set<String> all = new HashSet<String>();
		all.addAll(getClientConfigurationLocations());
		all.addAll(getServerConfigurationLocations());
		return all;
	}

	public ServicePackageConfiguration addDependancy(ServicePackageConfiguration config) {
		dependancies.add(config);
		return this;
	}
	
}
